//package com.anche.cywebnew.Utils.Shiro;
//
//import com.anche.cywebnew.Pojo.systemManager.SysResource;
//import com.anche.cywebnew.Pojo.systemManager.SysUser;
//import com.anche.cywebnew.Service.configManager.ResourceService;
//import com.anche.cywebnew.Service.securityManager.SecurityLogService;
//import com.anche.cywebnew.Utils.Spring.SpringBeanFactoryUtils;
//import org.apache.shiro.SecurityUtils;
//import org.apache.shiro.web.filter.AccessControlFilter;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import java.util.List;
//import java.util.Objects;
//
///**
// * @program: cywebnew
// * @description:
// * @author: LCHQ
// * @create: 2021-11-24 12:24
// */
//public class CoreBussinessFilter extends AccessControlFilter {
//    private static final Logger logger = LoggerFactory
//            .getLogger(CoreBussinessFilter.class);
//
//    @Override
//    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
//        return false;
//    }
//
//    @Override
//    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
//        System.out.println("执行了TestInterceptor的preHandle方法");
//        try {
//            //统一拦截（查询当前session是否存在user）(这里user会在每次登陆成功后，写入session)
//            SecurityLogService securityLogService = (SecurityLogService) SpringBeanFactoryUtils.getBean(SecurityLogService.class);   // 通过bean工厂获取SecurityLogService对象
//            ResourceService resourceService = (ResourceService) SpringBeanFactoryUtils.getBean(ResourceService.class);   // 通过bean工厂获取ResourceService对象
//
//            String path = ((HttpServletRequest)request).getRequestURI();
//            String method = ((HttpServletRequest)request).getMethod();
//            List<SysResource> resources = resourceService.getResourceByUrl(path.replaceAll("/cyweb/", ""));
//            SysUser curruser = (SysUser) SecurityUtils.getSubject().getPrincipal();     // 获取当前登录用户信息
//
//            if (Objects.nonNull(resources) && Objects.nonNull(curruser)){
//
//                resources.forEach(item->{
//                    if ("1".equals(item.getIscore())){   // 调用核心功能
//                        securityLogService.insertSecurityLog("核心功能", "用户【" +curruser.getLoginname() + "】调用核心功能URL【" + item.getUrl() + "】【" + item.getName() + "】", curruser);
//                    }
//                    if ("1".equals(item.getIsnormal())){  // 调用非常规功能
//                        securityLogService.insertSecurityLog("非常规业务", "用户【" +curruser.getLoginname() + "】调用非常规业务URL【" + item.getUrl() + "】【" + item.getName() + "】", curruser);
//                    }
//                });
//            }else {
//                logger.info("地址【" + path + "】不在资源表里,或未登录");
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return true;
//    }
//}
